package org.lanqiao.tjut.bzhDemo;

public class Student {
	// 姓名
	private String stuName;
	// 年龄
	private int stuAge;

	public Student() {
	}

	
	public Student(String stuName, int stuAge) {
		super();
		this.stuName = stuName;
		this.stuAge = stuAge;
	}

	
	@Override
	public boolean equals(Object obj) {
		// 子类实现equals的判定业务逻辑
		if(obj == null){
			//被比较对象为null:不等
			return false;
		}		
		if(this == obj){
			//地址相同，内容可定相同
			return true;
		}		
		//if(!(obj instanceof Student))
		if(this.getClass() != obj.getClass()){
			//两个比较类的定义类的类型不同，说明是两个不同类型的类，肯定不等
			return false;
		}
		// 类类型相同，进一步判定内容是否相同
		// 将obj转换成student类型，然比较内容
		Student stuObj = (Student) obj;
		// 判定类的内容是否相同：根据业务逻辑要求各个属性逐一进行判定内容是否相同
		if (this.getStuName().equals(stuObj.getStuName()) && this.getStuAge() == stuObj.getStuAge()) {
			return true;
		} else {
			return false;
		}
	}

	

	@Override
	public String toString() {
		return "Student [stuName=" + stuName + ", stuAge=" + stuAge + "]";
	}


	public String getStuName() {
		return stuName;
	}

	public void setStuName(String stuName) {
		this.stuName = stuName;
	}

	public int getStuAge() {
		return stuAge;
	}

	public void setStuAge(int stuAge) {
		this.stuAge = stuAge;
	}

}
